<?php
class ControllerCommonTask extends Controller {
    private $api_key = "4b5d871f2ee54468bf7580ba49656cc6";
    //send paid order message to cooker
    public function spomtc()
    {
        if (isset($this->request->get['api_key'])) {
            $apk = $this->request->get['api_key'];
        } else {
            $apk = '';
        }
        
        if($apk != $this->api_key)
        {
            echo 'error api_key';
            return ;
        }
        
        $this->load->model('tool/mqs');
        $this->load->model('tool/messager');
        $this->load->model('account/order');
        $msg = $this->model_tool_mqs->receiveOrderPaidMessage();
        if($msg)
        {
            $order_id = $msg['MessageBody'];
            $order_info = $this->model_account_order->getOrderBySystem($order_id);
            echo json_encode($order_id);
            if($order_info)
            {
                echo json_encode($order_info);
                if($this->model_tool_messager->sendOrderPaidMessageToCooker($order_info['cooker_contact'],$order_info['customer_name']))
                {
                    $this->model_tool_mqs->deleteOrderPaidMessage($msg);
                }
            }
        }
    }
}